<?php


abstract class Reg
{
    public $step = 'step1';
    /**
     * @var Reg
     */
    public $next = null;//下一节点
    /**
     * @var Reg
     */
    public $prev = null;//上一节点

    /**
     * 连接
     * @param Reg $object
     */
    public function setNextStep(Reg $object){
        $this->next = $object;
        $object->prev = $this;
    }
    public function stepNext($user){
        //只有当user的step和自己step相等时才会处理
        if ($user->step == $this->step){
            if ($this->next){
                //叫控制权
                $user->step = $this->next->step;
                return $user;
            }
        }else{
            if ($this->next){
                return $this->next->stepNext($user);
            }
        }
    }
}